package org.streets.workflow.engine.task;

import org.streets.workflow.engine.ITaskInstance;
import org.streets.workflow.engine.WorkflowEngine;
import org.streets.workflow.engine.WorkflowException;
import org.streets.workflow.engine.persistence.IWorkflowDAO;


/**
 *
 */
public class DefaultFormTaskCompletionEvaluator implements ITaskEvaluator{

    /* (non-Javadoc)
     * @see org.fireflow.engine.taskinstance.ITaskInstanceCompletionEvaluator#taskInstanceCanBeCompleted(org.fireflow.engine.IWorkflowSession, org.fireflow.engine.RuntimeContext, org.fireflow.engine.IProcessInstance, org.fireflow.engine.ITaskInstance)
     */
    public boolean eval(WorkflowEngine engine, ITaskInstance task)throws WorkflowException {
        IWorkflowDAO persistenceService = engine.getRuntimeContext().getPersistenceService();
        Integer aliveWorkItemCount = persistenceService.countAliveWorkItem(task.getId());
        if (aliveWorkItemCount == null || aliveWorkItemCount.intValue() == 0) {
            return true;
        } else {
            return false;
        }
    }
}
